package com.bit.inmap;

import android.os.Bundle;
import android.app.Activity;
import android.content.Intent;
import android.database.Cursor;
import android.view.KeyEvent;
import android.view.Menu;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.TextView;

public class LoginInfoActivity extends Activity implements OnClickListener{
	MySQLHandler handler;
	String tvName, tvId, tvPhone, tvEmail, tvBirth; 
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_login_info);
		handler = MySQLHandler.open(getApplicationContext());
		
		Button okBtn = (Button) this.findViewById(R.id.okBtn);
		okBtn.setOnClickListener(this);		
		
		Cursor c = handler.selectAll();
		if(c !=null){
			c.moveToFirst();
		}
		
		while(c.moveToNext()){
			tvName = c.getString(c.getColumnIndex("name"));
			tvId = c.getString(c.getColumnIndex("id"));
			tvPhone = c.getString(c.getColumnIndex("phone"));
			tvEmail = c.getString(c.getColumnIndex("email"));
			tvBirth = c.getString(c.getColumnIndex("birth"));
		}
		handler.close();
		
		TextView name = (TextView) findViewById(R.id.name_view);
		TextView id = (TextView) findViewById(R.id.id_view);
		TextView phone = (TextView) findViewById(R.id.phone_view);
		TextView email = (TextView) findViewById(R.id.email_view);
		TextView birth = (TextView) findViewById(R.id.birth_view);
		name.setText(tvName);
		id.setText(tvId);
		phone.setText(tvPhone);
		email.setText(tvEmail);
		birth.setText(tvBirth);
		
	}

	@Override
	public boolean onCreateOptionsMenu(Menu menu) {
		// Inflate the menu; this adds items to the action bar if it is present.
		getMenuInflater().inflate(R.menu.login_info, menu);
		return true;
	}

	@Override
	public void onClick(View v) {
		// TODO Auto-generated method stub
		switch(v.getId()){
			case R.id.okBtn:
				Intent intent = new Intent(this, MainActivity.class);
				intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);	// 메인이동후 이전 액티비티 스택 비우기(스택에 쌓인 액티비티 삭제)
				startActivity(intent);
			break;
			
		}
	}
	// Back 백튼 금지
	@Override
	public boolean onKeyDown(int keyCode, KeyEvent event) {
		switch (keyCode) {
		case KeyEvent.KEYCODE_BACK:
			return true;
		}
		return super.onKeyDown(keyCode, event);
	}

}
